﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace WinCSharp
{
    public partial class ShadowCopyFilesForm : Form
    {
        public ShadowCopyFilesForm()
        {
            InitializeComponent();
        }


        //加载一个ＤＬＬ　并执行里面的方法，
        //神奇之处在于，这个DLL 可以随时被替换为新的.
        //MyClass.dll 放于 Resouce\
        private void ShadowCopyFilesForm_Load(object sender, EventArgs e)
        {
            AppDomainSetup setup = new AppDomainSetup();
            setup.ShadowCopyFiles = "true";
            setup.CachePath = @"E:\Projects\TestProject\TestProject\bin";
            setup.ApplicationName = "abc";
            AppDomain myDomain = AppDomain.CreateDomain("myDomain", null, setup);

            Assembly a = myDomain.Load("MyClass");
            //Assembly a = Assembly.Load("MyClass");
            Type t = a.GetType("MyClass.Class1");
            MethodInfo m = t.GetMethod("getName");
            object obj = Activator.CreateInstance(t);
            object name = m.Invoke(obj, null);


            MessageBox.Show(name.ToString());
        }
    }
}


/*
 
namespace MyClass
{
    public class Class1
    {
        public string getName()
        {
            return "CC";
        }
    }
}
 
 */
